﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lapkin.Attributes;
using Lapkin.Models.DataModels;
using Lapkin.Models.Repositories;

namespace Lapkin.Areas.Admin.Controllers
{
    [Authorize(Roles = "Admin")]
    public class ProductController : Controller
    {
        private readonly SqlRepository _repository = new SqlRepository();
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost, IsAjax]
        public JsonResult ListProperty()
        {
            IEnumerable<Product> products = _repository.ProductRepository.GetListProduct();
            var filteringProducts =
                from p in products
                select new
                    {
                        Id = p.Id,
                        Name = p.Name,
                        Alias = p.Alias,
                        Price = p.Price,
                        IsActive = p.IsActive
                    };
            return Json(new { Result = "OK", Records = filteringProducts });
        }

        [HttpGet]
        public ActionResult Add()
        {
            return View(new Product());
        }

        [HttpGet]
        public ActionResult Edit(Guid id)
        {
            return View(new Product());
        }
    }
}
